o = [int(i)for i in input().split()]
n = o[0]
k = o[1]
z = {}
for i in range(n):
    a = input()
    for j in a:
        if(j not in z):
            z[j] = 1
        else:
            z[j] += 1
max = 0
maxa = 'z'
for i in range(k):
    for j in z:
        if(z[j] > max):
            max = z[j]
            maxa = j
        elif(z[j] == max):
            max = z[j]
            maxa = j
    print(maxa, ' ', max)
    maxa = 0
